/**
 * Copyright (c) 2006-2007, Julien PORTALIER
 * 
 * Licensed under The LGPL License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @copyright  Copyright (c) 2006-2007, Julien PORTALIER
 * @link       http://feather-cm.googlecode.com/
 * @license    http://www.opensource.org/licenses/lgpl-license.php The LGPL License
 */

var AdaptiveScreenLayout = new Class(
{
	initialize: function()
	{
		this.sizes = [
			'medium',
			'intermediate',
			'small',
			'handled',
			'cellphone'
		];
		
		this.resize();
		window.addEvent('resize', this.resizeWithDelay.bind(this));
	},
	
	resizeWithDelay: function()
	{
		$clear(this.timer);
		this.timer = this.resize.delay(10, this);
	},
	
	resize: function()
	{
		var mainPage = $('mainPage');
		if (mainPage) 
		{
			var size = $('mainPage').offsetWidth;
			var _class = null;
			
			if (size < 400) 
				_class = 'cellphone';
			else if (size < 620) 
				_class = 'handled';
			else if (size < 770) 
				_class = 'small';
			else if (size < 840) 
				_class = 'intermediate';
			else if (size < 970) 
				_class = 'medium';
			
			this.setSize(_class);
		}
	},
	
	setSize: function(className)
	{
		var body = $(document.body);
		if (!className || !body.hasClass(className))
		{
			this.sizes.each(function(_className) {
				body.removeClass(_className);
			});
			if (className) {
				body.addClass(className);
			}
		}
	}
});

window.addEvent('domready', function() { new AdaptiveScreenLayout(); });